﻿using System;
using System.Collections.Generic;
using System.IO;
using BSDS.Commands.Commands;
using BSDS.Commands.Commands.Creation.Implementation;
using BSDS.Core.Model.Services;
using BSDS.Core.Model.Services.Jobs;
using BSDS.Core.Data.Local;

namespace BSDS.Service.Commands
{
    public class ServiceDownloadCommandCreator : DownloadCommandCreator
    {
        public ServiceDownloadCommandCreator(DownloadService downloadService, JobService jobService, JobRepository jobRepository, 
            DataRepository dataRepository) : base(downloadService, jobService, jobRepository, dataRepository)
        {
        }

        protected override ICommand Create(Dictionary<string, string> parameters)
        {
            var defaultConfig = CreateConfiguration(parameters);
            var extension = defaultConfig.Format.Value;

            // Override default pipe extension for portal compatibility
            if (defaultConfig.Portal && defaultConfig.Format == DataFormat.Pipe)
            {
                extension = "txt";
            }

            defaultConfig.OutFile = "..\\downloaded\\" + defaultConfig.DataSourceName + DateTime.Now.ToString("_yyyy-MM-dd.") + extension;

            return Create(defaultConfig);
        }
    }
}